package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.SmartDevice;
import com.dwxt.sport.business.entity.SmartDeviceEquipment;
import com.dwxt.sport.business.service.SmartDeviceService;
import com.dwxt.sport.business.vo.smartDevice.InsertOrUpdateSmartDeviceEquipmentVo;
import com.dwxt.sport.business.vo.smartDevice.InsertOrUpdateSmartDeviceVo;
import com.dwxt.sport.business.vo.smartDevice.SelectSmartDeviceVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 智能装备
 *
 * @author Kuang.JiaZhuo
 * @date 2020-07-29 11:51
 */
@RestController
@RequestMapping("/smartDevice")
@Api(tags={"智能装备相关接口"})
public class SmartDeviceController {

    @Resource
    SmartDeviceService smartDeviceService;

    @ApiOperation(value = "新增智能装备", notes = "新增智能装备", response = Integer.class)
    @PostMapping("/back/insertSmartDevice")
    public BaseResult insertSmartDevice(InsertOrUpdateSmartDeviceVo insertVo){
        int result = this.smartDeviceService.insertSmartDevice(insertVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "更新智能装备", notes = "更新智能装备", response = Integer.class)
    @PostMapping("/back/updateSmartDevice")
    public BaseResult updateSmartDevice(InsertOrUpdateSmartDeviceVo updateVo){
        int result = this.smartDeviceService.updateSmartDevice(updateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "获取智能装备列表", notes = "按条件查询智能装备列表(带分页)", response = SmartDevice.class)
    @PostMapping("/back/selectSmartDeviceByCondition")
    public BaseResult selectSmartDeviceByCondition(SelectSmartDeviceVo selectVo){
        PageInfo<SmartDevice> pageInfo = this.smartDeviceService.selectSmartDeviceByCondition(selectVo);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除智能装备", notes = "根据ids批量删除智能装备", response= Integer.class)
    @PostMapping(value = "/back/deleteSmartDeviceByIds")
    public BaseResult deleteSmartDeviceByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.smartDeviceService.deleteSmartDeviceByIds(ids);
        return BaseResult.ok(result);
    }

    /******************************************************************  关联设备  ******************************************************************************/


    @ApiOperation(value = "删除智能装备关联设备", notes = "根据ids批量删除能装备关联设备", response= Integer.class)
    @PostMapping(value = "/back/deleteSmartDeviceEquipmentByIds")
    public BaseResult deleteSmartDeviceEquipmentByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.smartDeviceService.deleteSmartDeviceEquipmentByIds(ids);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "查询智能装备关联的设备列表", notes = "根据智能装备的id查询关联设备的列表(带分页)", response= SmartDeviceEquipment.class)
    @PostMapping(value = "/back/getOutdoorFitnessEquipmentByPage")
    public BaseResult selectSmartDeviceEquipmentByCondition(@ApiParam(value = "智能装备id", required = true) @RequestParam String id,
                                                            @ApiParam(value = "起始页", required = true) @RequestParam Integer pageNum,
                                                            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize){
        String smartDeviceId = id;
        PageInfo<SmartDeviceEquipment> pageInfo = this.smartDeviceService.selectSmartDeviceEquipmentByCondition(pageNum,pageSize,smartDeviceId);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "新增或更新智能装备的设备关联", notes = "新增或更新智能装备关联的设备", response = Integer.class)
    @PostMapping("/back/insertOrUpdateSmartDeviceEquipment")
    public BaseResult insertOrUpdateSmartDeviceEquipment(InsertOrUpdateSmartDeviceEquipmentVo insertOrUpdateVo){
        int result = this.smartDeviceService.insertOrUpdateSmartDeviceEquipment(insertOrUpdateVo);
        return BaseResult.ok(result);
    }



}
